<template>
    <div class="pageCon">
        <div class="bc"></div>
        <div class="main">
            <div class="cartList">
                <div class="selectAll">
                    <input type="checkbox" @click="selectAllFn" v-model="selectAll" />
                    全选
                </div>
                <CartItem v-for="item in useCart.cartList" :cartItem="item" :key="item"></CartItem>
            </div>
            <div class="total">
                <div class="item totalCount">
                    <div class="key"> 订单小计:</div>
                    <div class="value">已选 {{ useCart.totalNum }}件商品</div>
                </div>
                <div class="item totalPrice">
                    <div class="key"> 总计:</div>
                    <div class="value">{{ useCart.total }}</div>

                </div>
                <div class="item otherPrice">
                    <div class="key"> 配送费: </div>
                    <div class="value"> {{ useCart.otherPrice }}</div>
                </div>
                <div class="item allPrice">
                    <div class="key"> 合计: </div>
                    <div class="value allPrice"> {{ useCart.total + useCart.otherPrice }}</div>
                </div>
                <div class="msg">
                    <div>愿每位光临的顾客都能感受到我们用心烘焙的幸福味道，享受甜蜜每一刻，生活如蛋糕般美满！</div>
                </div>
                <button class="buyBtn" @click="goBuy">立即结算</button>
            </div>

        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useCartStore } from '@/stores/cart';
import { useRouter } from 'vue-router'
const router = useRouter()
const useCart = useCartStore();
const selectAll = ref(false)
import CartItem from '@/components/CartItem.vue';

onMounted(() => {
    useCart.getCartList()
})

const selectAllFn = () => {
    useCart.selectAll(!selectAll.value)
}

const goBuy = () => {
    console.log('goBuy');
    router.push('/buy')
}
</script>
<style lang="scss" scoped>
.pageCon {
    display: flex;
    flex-direction: column;
    align-items: center;

    .bc {
        width: 100%;
        height: 35rem;
        background-image: url('@/assets/cartBC.jpg');
        background-size: cover;
        background-position: center;
    }

    .main {
        display: flex;
        width: 80%;
        padding: 20px;
        box-sizing: border-box;
        gap: 30px;

        .cartList {
            .selectAll {
                padding: 20px;
                width: 100%;
                background-color: #f9f9f9;
            }

            display: flex;
            flex-direction: column;
            align-items: center;
            width:80%;
        }

        .total {
            height: 400px;
            width: 20%;
            position: sticky;
            padding: 30px;
            box-sizing: border-box;
            top: 10vh;
            left: 67%;
            gap: 10px;
            display: flex;
            flex-direction: column;
            background-color: #f9f9f9;

            .item {
                display: flex;
                justify-content: space-between;
                align-items: center;
                position: relative;

                &.totalCount {
                    padding-bottom: 4px;


                    &::after {
                        content: '';
                        bottom: 0px;
                        position: absolute;
                        display: block;
                        width: 100%;
                        height: 1px;
                        background-color: #ccc;
                        margin-top: 10px;
                    }
                }

                .key {
                    color: #6e6e6e;
                    font-weight: 600;
                }

                .value {
                    font-weight: 600;

                    &.allPrice {
                        font-size: 30px;
                    }
                }

                &.allPrice {
                    margin-top: 20px;

                    &::after {
                        content: '';
                        bottom: 0px;
                        position: absolute;
                        display: block;
                        width: 100%;
                        height: 1px;
                        background-color: #ccc;
                        margin-top: 10px;
                    }
                }
            }

            .msg {
                color: #6e6e6e;
                font-weight: 600;
                display: flex;
                flex-direction: column;
                gap: 10px
            }

            .buyBtn {
                margin-top: 20px;
                width: 100%;
                padding: 10px;
                background-color: black;
                color: white;
                text-align: center;
                border: none;
                cursor: pointer;
            }
        }
    }
}
</style>